package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class MovieAdapter extends ArrayAdapter<Movie> {
    private int resourceId;
    private List<Movie> movieData;
    public MovieAdapter(@NonNull Context context, int resource,  @NonNull List objects) {
        super(context, resource,  objects);
        resourceId = resource;
        movieData = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Movie movie = getItem(position);
        View movieView = LayoutInflater.from(getContext()).inflate(resourceId,null);
        ImageView movieImg = movieView.findViewById(R.id.img_movie);
        TextView movieText = movieView.findViewById(R.id.text_movie);
        movieImg.setImageResource(movie.getImg());
        movieText.setText(movie.getName());
        return movieView;

    }
}
